<!DOCTYPE html>
<html>

<include file="./Application/Admin/View/common/css-js.html"/>
<link rel="stylesheet" type="text/css" href="/Public/layui/css/layui.css" />
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <a style="float: left;display: inline-block;width: 30px" href="javascript:history.go(-1);"><i class="fa fa-reply" aria-hidden="true"></i></a>
                    <h5>添加|修改商品</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="add_member" id="ajaxForm" method="post" action="/index.php/Admin/Shop/edit">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商品名称：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" name="goods_name" placeholder="请输入商品名称" value="{$info['goods_name']}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商品货号：</label>
                            <div class="input-group col-sm-4">
                                <input  type="text" class="form-control" name="goods_sn" value="{$info['goods_sn']}" placeholder="请输入商品货号，如果不输入系统将自动生成">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商品图片：</label>
                            <div class="input-group col-sm-4">
                                <input type="hidden"  name="goods_img" class="goods_img" value="{$info['goods_img']}">
                                <if condition="$info['goods_img'] neq ''">
                                    <img src="{$info['goods_img']}" height="100px" width="100px" style="margin-right: 10px;"/>
                                    <button type="button" class="btn btn-danger" id="delete-img" style="margin-right: 5px;">删除图片</button>
                                    <else />
                                    <img src="{$info['goods_img']}" height="100px" width="100px" style="margin-right: 10px;display: none"/>
                                    <button type="button" class="btn btn-danger" id="delete-img" style="display: none;margin-right: 5px;">删除图片</button>
                                </if>

                                <button class="btn btn-primary" type="button" id="select-img"><i class="fa fa-save"></i> 选择图片</button>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商品价格：</label>
                            <div class="input-group col-sm-4">
                                <input type="text"  class="form-control" value="{$info['price']|fen_to_yuan}" name="price"  placeholder="请输入商品价格，单位元">
                            </div>
                        </div>
                        <!--<div class="form-group">
                            <label class="col-sm-3 control-label">用户等级价格：</label>
                            <div class="input-group col-sm-4">
                                <input type="number" class="form-control" value="{$info['price']}" name="price"  placeholder="请输入商品价格，单位元">
                            </div>
                        </div>-->
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商品库存：</label>
                            <div class="input-group col-sm-4">
                                <input type="number" class="form-control" name="storage" value="{$info['storage']}" placeholder="请输入商库存">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商品简介：</label>
                            <div class="input-group col-sm-4">
                                <textarea type="text" rows="5" name="goods_description"  placeholder="请输入商品描述" class="form-control">{$info['goods_description']}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label " for="myEditor">商品详情</label>
                            <div class="input-group col-sm-9">
                                <script src="/Public/ueditor/ueditor.config.js" type="text/javascript"></script>
                                <script src="/Public/ueditor/ueditor.all.js" type="text/javascript"></script>
                                <textarea name="content" style="width:90%;" id="myEditor">{$info['content']}</textarea>
                                <script type="text/javascript">
                                    var editor = new UE.ui.Editor({
                                        'initialFrameHeight':500
                                    });
                                    editor.render("myEditor");
                                </script>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否上架：</label>
                            <div class="input-group col-sm-4">
                                <if condition="$info.is_on_sale eq 0">
                                    <label><input type="radio" name="is_on_sale"  value="0" checked>否</label>&nbsp;&nbsp;&nbsp;
                                    <label><input type="radio" name="is_on_sale"  value="1">是</label>
                                    <else />
                                    <label><input type="radio" name="is_on_sale"  value="0">否</label>&nbsp;&nbsp;&nbsp;
                                    <label><input type="radio" name="is_on_sale"  value="1" checked>是</label>
                                </if>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <input type="hidden" name="id" value="{$info.id}">
                                <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<script src="/Public/layui/layui.js"></script>
<script>
    layui.use(['upload', 'layer'], function(){
        var upload = layui.upload;
        var layer = layui.layer;

        //拖拽上传
        upload.render({
            elem: '#select-img'
            ,url: '/index.php/Admin/Shop/uploadImg'
            ,accept: 'images'
            ,done: function(res){
                if (res.status == 1) {
                    $('#select-img').siblings('img').attr('src', res.src).show().siblings('#delete-img').show().siblings('.goods_img').val(res.src);
                    layer.msg(res.msg, {icon: 1});
                } else {
                    layer.msg(res.info, {icon: 2});
                }
            }
        });

        $('#delete-img').click(function () {
            var img = $(this).siblings('.goods_img').val();
            var data = {
                img: img
            }
            getData(data, '/index.php/Admin/Shop/deleteImg', function (res) {
                if(res.status == 1) {
                    $('#delete-img').hide().siblings('img').attr('src', '').hide().siblings('#delete-img').hide().siblings('.goods_img').val('');
                    layer.msg(res.info, {icon: 1});
                } else {
                    layer.msg(res.info, {icon: 2});
                }
            });
        });

        $("#ajaxForm").submit( function () {
            var self = $(this);
            var index = layer.load();
            $.ajax({
                type : "POST",
                cache: false,
                url  : self.attr("action"),
                data : self.serialize(),
                datatype : "json",
                success : function (res) {
                    layer.close(index);
                    if (res.status == 1) {
                        layer.msg(res.info, {icon: 1});
                    } else {
                        layer.msg(res.info, {icon: 2});
                    }
                },
                error: function(){
                    alert("程序错误!")
                }
            });
            return false;
        } );
        function getData(data,url,success) {
            $.ajax({
                type: "POST",
                url: url,
                dataType: 'json',
                timeout: 10000,
                data:data ,
                success: success
            });
        }
    })
</script>
</body>

</html>
